from playwright.sync_api import Page

class Xinzengzichan:
    def __init__(self,page:Page):
        self.page = page

    def navigate(self):
        self.page.goto("http://asset.dasu123.inet/#/asset-management/asset-checkin")
        self.page.wait_for_timeout(10000)

    def xinzengzichan(self,zichanmingchen):
        self.page.get_by_role("button", name="新增资产").click()
        self.page.wait_for_timeout(500)
        self.page.get_by_label("所属公司").click()
        self.page.wait_for_timeout(500)
        self.page.get_by_title("东莞盟大集团有限公司").get_by_text("东莞盟大集团有限公司").click()
        self.page.wait_for_timeout(500)
        #self.page.get_by_role("tabpanel", name="基础信息").locator("#name").click()
        self.page.get_by_role("tabpanel", name="基础信息").locator("#name").fill(zichanmingchen)
        self.page.wait_for_timeout(500)
        self.page.get_by_label("资产类别").click()
        self.page.get_by_title("图书档案").get_by_text("图书档案").click()
        self.page.wait_for_timeout(500)
        self.page.get_by_label("存放地").click()
        self.page.get_by_title("道滘仓库").get_by_text("道滘仓库").click()
        self.page.wait_for_timeout(500)
        self.page.get_by_role("button", name="提 交").click()
        self.page.wait_for_timeout(500)

        message=self.page.locator('.ant-notification-notice-description').inner_text()
        try:
            assert '操作成功' in message, "操作成功"
        except AssertionError as e:
            print('新增资产失败')

    def xinzengzichan2(self):
        self.page.get_by_role("button", name="新增资产").click()
        self.page.wait_for_timeout(500)
        self.page.get_by_role("button", name="提 交").click()
        self.page.wait_for_timeout(500)

